package com.car.util;

import java.util.List;

public class Page {
	
	/*-------------分页专用----------------*/
	/**
	 * 记录总数
	 */
	private long total;
	/**
	 * 一页显示数目
	 */
	private long pagesize = 15;
	/**
	 * 总的页数
	 */
	private long pagetotal;
	/**
	 * 当前显示页
	 */
	private long currpage;
	private long nextpage;
	private long previouspage;
	private long lastpage;
	private long firstrownum;
	private long lastrownum;
	private List root;
	
	private String parmeterUrl;
	public List getRoot() {
		return root;
	}

	public void setRoot(List root) {
		this.root = root;
	}

	/**
	 * @return Returns the currentPage.
	 */
	public long getCurrpage() {
		return currpage;
	}

	/**
	 * @param currentPage
	 *            The currentPage to set.
	 */
	public void setCurrpage(long currpage) {
		this.currpage = currpage;
	}

	/**
	 * @return Returns the pageSize.
	 */
	public long getPagesize() {
		return pagesize;
	}

	/**
	 * @param pageSize
	 *            The pageSize to set.
	 */
	public void setPagesize(long pageSize) {
		this.pagesize = pageSize;
	}

	/**
	 * @return Returns the totalNum.
	 */
	public long getTotal() {
		return total;
	}

	/**
	 * @return Returns the totalPage.
	 */
	public long getPagetotal() {
		return pagetotal;
	}

	/**
	 * @return Returns the lastpage.
	 */
	public long getLastpage() {
		this.lastpage = this.pagetotal;
		return lastpage;
	}

	/**
	 * @return Returns the nextpage.
	 */
	public long getNextpage() {
		if (this.currpage > this.pagetotal) {
			this.nextpage = this.lastpage;
		} else {
			this.nextpage = this.currpage + 1;
		}
		return nextpage;
	}

	/**
	 * @return Returns the previouspage.
	 */
	public long getPreviouspage() {
		if (this.currpage == 1) {
			this.previouspage = 1;
		} else {
			this.previouspage = this.currpage - 1;
		}
		if (this.previouspage < 0) {
			this.previouspage = 0;
		}
		return previouspage;
	}

	public void checkPage() {
		if (this.pagesize == 0) {
			/**
			 * 默认分页15条
			 */
			this.pagesize = 15;
		}
		this.pagetotal = this.total /this.pagesize;
		if (this.pagetotal * this.pagesize < this.total) {
			this.pagetotal = this.pagetotal + 1;
		}
		if (this.currpage > this.pagetotal) {
			this.currpage = this.pagetotal;
		}
		if (this.currpage <= 0) {
			/**
			 * 默认第一页
			 */
			if (this.pagetotal == 0) {
				this.currpage = 0;
			} else {
				this.currpage = 1;
			}
		}
		firstrownum = (this.currpage - 1) * this.pagesize;
		if (firstrownum < 0) {
			firstrownum = 0;
		}
		lastrownum = firstrownum + this.pagesize;
		if (lastrownum >= this.total) {
			lastrownum = this.total;
		}
	}
	
	public void setTotal(long total) {
		this.total = total;
		this.checkPage();
	}

	public void setPagetotal(int pagetotal) {
		this.pagetotal = pagetotal;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public void setPreviouspage(int previouspage) {
		this.previouspage = previouspage;
	}

	public void setLastpage(int lastpage) {
		this.lastpage = lastpage;
	}

	public long getFirstrownum() {
		firstrownum = (this.currpage - 1) * this.pagesize;
		if (firstrownum < 0) {
			firstrownum = 0;
		}
		return firstrownum;
	}

	public void setFirstrownum(Long firstrownum) {
		this.firstrownum = firstrownum;
	}

	public long getLastrownum() {
		return lastrownum;
	}

	public void setLastrownum(int lastrownum) {
		this.lastrownum = lastrownum;
	}

	public String getParmeterUrl() {
		return parmeterUrl;
	}

	public void setParmeterUrl(String parmeterUrl) {
		this.parmeterUrl = parmeterUrl;
	}



}
